package top.huxy.boot.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.huxy.boot.exception.RequestAbortedException;
import top.huxy.boot.mapper.ShareSiteMapper;
import top.huxy.boot.model.dto.DTO_AddShareSite;
import top.huxy.boot.service.ShareSiteService;
import top.huxy.boot.util.IPAddressUtils;
import top.huxy.boot.util.RequestUtils;

/**
 * @author HuXY
 * @since 2021-12-14 14:34:49
 */
@Service
public class ShareSiteServiceImpl implements ShareSiteService {
    @Autowired
    private ShareSiteMapper shareSiteMapper;

    @Override
    public void insert(DTO_AddShareSite dtoAddShareSite) {
        dtoAddShareSite.setCreateTime(System.currentTimeMillis());
        dtoAddShareSite.setIp(IPAddressUtils.getRequestIp());
        dtoAddShareSite.setRequestId(RequestUtils.getRequestID());
        int res = shareSiteMapper.insert(dtoAddShareSite);
        if (res == 0) {
            throw new RequestAbortedException("未新增任何数据");
        }
        if (res > 1) {
            throw new RequestAbortedException("不是预期的结果");
        }
    }
}

